#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef enum {
    TOKEN_T, TOKEN_F, TOKEN_AND, TOKEN_OR, TOKEN_NOT, TOKEN_LPAREN, TOKEN_RPAREN, TOKEN_END
} TokenType;

typedef struct {
    TokenType type;
    char value;
} Token;

Token currentToken;
const char *input;
int pos;

Token getNextToken() {
    if (pos >= strlen(input)) {
        currentToken.type = TOKEN_END;
        return currentToken;
    }

    char ch = input[pos++];
    switch (ch) {
        case 'T': currentToken.type = TOKEN_T; break;
        case 'F': currentToken.type = TOKEN_F; break;
        case '&': currentToken.type = TOKEN_AND; break;
        case '|': currentToken.type = TOKEN_OR; break;
        case '!': currentToken.type = TOKEN_NOT; break;
        case '(': currentToken.type = TOKEN_LPAREN; break;
        case ')': currentToken.type = TOKEN_RPAREN; break;
        default: fprintf(stderr, "Invalid character: %c\n", ch); exit(1);
    }
    currentToken.value = ch;
    return currentToken;
}

char expr();

char factor() {
    Token token = currentToken;
    if (token.type == TOKEN_T || token.type == TOKEN_F) {
        getNextToken();
        return token.value;
    } else if (token.type == TOKEN_LPAREN) {
        getNextToken();
        char result = expr();
        if (currentToken.type != TOKEN_RPAREN) {
            fprintf(stderr, "Expected ')'\n");
            exit(1);
        }
        getNextToken();
        return result;
    } else if (token.type == TOKEN_NOT) {
        getNextToken();
        char result = factor();
        return (result == 'T') ? 'F' : 'T';
    } else {
        fprintf(stderr, "Expected factor\n");
        exit(1);
    }
}

char term() {
    char left = factor();
    while (currentToken.type == TOKEN_AND) {
        getNextToken();
        char right = factor();
        left = (left == 'T' && right == 'T') ? 'T' : 'F';
    }
    return left;
}

char expr() {
    char left = term();
    while (currentToken.type == TOKEN_OR) {
        getNextToken();
        char right = term();
        left = (left == 'T' || right == 'T') ? 'T' : 'F';
    }
    return left;
}

char evaluateExpression(const char *expression) {
    input = expression;
    pos = 0;
    getNextToken();
    return expr();
}

int main() {
    char expr[50];
    if (fgets(expr, sizeof(expr), stdin) != NULL) {
        expr[strcspn(expr, "\n")] = '\0';
        printf("%c", evaluateExpression(expr));
    } else {
        fprintf(stderr, "Failed to read input\n");
        return 1;
    }
    return 0;
}